/*
 * @lc app=leetcode.cn id=242 lang=javascript
 *
 * [242] 有效的字母异位词
 */

// @lc code=start
/**
 * @param {string} s
 * @param {string} t
 * @return {boolean}
 */
var isAnagram = function(s, t) {
    if (s.length !== t.length) {
        return false
    }
    const sObj = new Map()
    const tObj = new Map()
    for (let index = 0; index < s.length; index++) {
        const element1 = s[index];
        const element2 = t[index];
        if(sObj.get(element1)) {
            sObj.set(element1, sObj.get(element1) + 1)
        } else {
            sObj.set(element1, 1)
        }
        if(tObj.get(element2)) {
            tObj.set(element2, tObj.get(element2) + 1)
        } else {
            tObj.set(element2, 1)
        }
    }
    let flag = true
    for (const [key, val] of sObj) {
        if (val !== tObj.get(key)) {
            flag = false
        }
    }
    return flag
};
// @lc code=end

